package com.trs.touch.event.demo;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.LinearLayout;

/**
 * Created by Administrator on 2015/12/10.
 */
public class MyLayout extends LinearLayout {
    public MyLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                System.out.println("MyLayout--dispatchTouchEvent:" + "---MotionEvent.ACTION_DOWN---");
                break;
            case MotionEvent.ACTION_MOVE:
                System.out.println("MyLayout--dispatchTouchEvent:" + "---MotionEvent.ACTION_MOVE---");
                break;
            case MotionEvent.ACTION_UP:
                System.out.println("MyLayout--dispatchTouchEvent:" + "---MotionEvent.ACTION_UP---");
                break;
            case MotionEvent.ACTION_CANCEL:
                System.out.println("MyLayout--dispatchTouchEvent:" + "---MotionEvent.ACTION_CANCEL---");
                break;
            default:
                break;
        }
        // returen true 表示不向下继续传递,false 则继续向下传递
//        return false;
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                System.out.println("MyLayout--onInterceptTouchEvent:" + "---MotionEvent.ACTION_DOWN---");
                break;
            case MotionEvent.ACTION_MOVE:
                System.out.println("MyLayout--onInterceptTouchEvent:" + "---MotionEvent.ACTION_MOVE---");
                break;
            case MotionEvent.ACTION_UP:
                System.out.println("MyLayout--onInterceptTouchEvent:" + "---MotionEvent.ACTION_UP---");
                break;
            case MotionEvent.ACTION_CANCEL:
                System.out.println("MyLayout--onInterceptTouchEvent:" + "---MotionEvent.ACTION_CANCEL---");
                break;
            default:
                break;
        }
        // returen true 表示不向下继续传递,false 则继续向下传递
        return super.onInterceptTouchEvent(ev);
//        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                System.out.println("MyLayout--onTouchEvent:" + "---MotionEvent.ACTION_DOWN---");
                break;
            case MotionEvent.ACTION_MOVE:
                System.out.println("MyLayout--onTouchEvent:" + "---MotionEvent.ACTION_MOVE---");
                break;
            case MotionEvent.ACTION_UP:
                System.out.println("MyLayout--onTouchEvent:" + "---MotionEvent.ACTION_UP---");
                break;
            case MotionEvent.ACTION_CANCEL:
                System.out.println("MyLayout--onTouchEvent:" + "---MotionEvent.ACTION_CANCEL---");
                break;
            default:
                break;
        }
        // returen true 表示不向下继续传递,false 则继续向下传递
//        return super.onTouchEvent(ev);
        return false;
    }
}
